package com.tianji.learning.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionAdminVO;
import com.tianji.learning.domain.vo.QuestionVO;
import org.springframework.web.bind.annotation.*;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 控制器
 * </p>
 *
 * @author author
 */
@Api(tags = "InteractionQuestion管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/questions")
public class InteractionQuestionController {

    private final IInteractionQuestionService interactionQuestionService;

    /**
     * 新增InteractionQuestion
     *
     * @param dto
     */
    @ApiOperation("新增InteractionQuestion")
    @RequestMapping()
    public void saveInteractionQuestion(@Valid @RequestBody QuestionFormDTO dto) {
        interactionQuestionService.saveInteractionQuestion(dto);

    }

    /**
     * 分页查询InteractionQuestion
     *
     * @return
     */
    @ApiOperation("分页查询InteractionQuestion")
    @GetMapping("/page")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery dto) {
        return interactionQuestionService.queryQuestionPage(dto);
    }

    /**
     * 根据id查询问题详情
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id查询问题详情")
    @GetMapping("{id}")
    public QuestionVO queryQuestionById(@PathVariable("id") Long id) {
        return interactionQuestionService.queryQuestionById(id);
    }

    /**
     * 修改问题
     *
     * @param id
     * @param dto
     */
    @ApiOperation("修改问题")
    @PutMapping("/{id}")
    public void updateQuestion(@PathVariable("id") Long id, @RequestBody QuestionFormDTO dto) {
        interactionQuestionService.updateQuestion(id, dto);
    }

    @ApiOperation("删除我的问题")
    @DeleteMapping("{id}")
    public void deleteMyQuestion(@PathVariable("id") Long id) {
        interactionQuestionService.deleteMyQuestion(id);
    }

}

